#include<bits/stdc++.h>
#define ONLINE_JUDGE
#define ll long long
#define ull unsigned long long
#define ls (x << 1)
#define rs (x << 1 | 1)
using namespace std;

const ll N = 6e5 + 10, INF = 0x3f3f3f3f;

ll n, q, id;
struct node
{
    ll l, r, mi;
    ll len() { return r - l + 1; }
}t[N * 4];
ll hs[N];

void pushup(ll x)
{
    if (t[ls].mi < t[rs].mi)  t[x].mi = t[ls].mi;
    else t[x].mi = t[rs].mi;
}

void build(ll x, ll l, ll r)
{
    t[x].l = l, t[x].r = r;
    if (l == r) {
        cin >> t[x].mi;
        hs[t[x].mi] = t[x].l;
        return;
    }
    ll mid = (l + r) >> 1;
    build(ls, l, mid);
    build(rs, mid + 1, r);
    pushup(x);
}

void modify(ll x, ll p, ll v)
{
    if (t[x].l == p && t[x].r == p) { t[x].mi = v;return; }
    ll mid = (t[x].r + t[x].l) >> 1;
    if (p <= mid) modify(ls, p, v);
    else modify(rs, p, v);
    pushup(x);
}

ll query(ll x, ll l, ll r)
{
    if (l > r || l <= 0 || r > n) return INF;
    if (t[x].l >= l && t[x].r <= r) {
        return t[x].mi;
    }
    ll res = INF, temp;
    ll mid = (t[x].l + t[x].r) >> 1;
    if (mid >= l) res = min(res, query(ls, l, r));
    if (mid < r) res = min(res, query(rs, l, r));
    return res;
}

void print(ll x)
{
    if (t[x].l == t[x].r) {
        cout << t[x].mi << ' ';
        return;
    }
    print(ls);
    print(rs);
}

void solve()
{
    cin >> n;
    build(1, 1, n);
    cin >> q;
    ll l, r;
    while (q--) {
        cin >> l >> r;
        ll mi = min(query(1, 1, l - 1), query(1, r + 1, n));
        if (mi >= n) { cout << "peace\n";continue; }
        cout << mi << '\n';
        ll _mi = mi + 1;
        ll id = hs[mi], _id = hs[_mi];
        modify(1, id, _mi);
        modify(1, _id, mi);
        swap(hs[mi], hs[_mi]);
    }
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}